// custom-tab-bar/index.js
import { storeBindingsBehavior } from 'mobx-miniprogram-bindings'
import { store } from '../store/store'

Component({
  options: {
    styleIsolation: 'shared'
  },
  behaviors: [storeBindingsBehavior],
  storeBindings: {
    store,
    fields: {
      active: 'activeTabBarIndex'
    },
    actions: {
      updateActiveTabBarIndex: 'updateActiveTabBarIndex'
    }
  },
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    "list": [{
      "text": "对象",
      "pagePath": "/pages/info/info",
      "iconPath": "/images/tabBar/icons8-elephant-64.png",
      "selectedIconPath": "images/tabBar/icons8-elephant-64.png"
    }, {
      "text": "点评",
      "pagePath": "/pages/message/message",
      "iconPath": "/images/雷.png",
      "selectedIconPath": "/images/雷.png"
    }, {
      "text": "我的",
      "pagePath": "/pages/my/my",
      "iconPath": "/images/tabBar/icons8-cat-64.png",
      "selectedIconPath": "images/tabBar/icons8-cat-64.png"
    }]
  },

  /**
   * 组件的方法列表
   */
  methods: {
    onChange(event) {
      // event.detail 的值为当前选中项的索引
      // this.setData({ active: event.detail });
      this.updateActiveTabBarIndex(event.detail)
      wx.switchTab({
        url: this.data.list[event.detail].pagePath,
      })
    },
  }
})